<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Python language</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Python, data types, tutorial, programming language, learn Python">
<meta name="description" content="In this chapter of the Python tutorial, we
introduce the Python language.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content">

<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>


<h1>Python language</h1>

<p>
In this part of the Python programming tutorial, we will talk about the 
Python programming language in general.
</p>

<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewSquare */
google_ad_slot = "0364418177";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 

<h2>Goal</h2>

<p>
The goal of this tutorial is to get you started with the Python 
programming language. Python is a great language to learn. It is an 
ideal language for those, who are new to programming. After reading 
this tutorial, you will be confident to continue your own studies.
You can create scripts, web sites, games or desktop applications in Python. 
Even if you do not want to become a programmer, Python may be a great 
tool for occasional programmers or hobbyists. 
</p>


<h2>Python</h2>

<p>
<img src="/img/lang/python/pythonlogo.png" style="float: left;" alt="python logo">
Python is a general-purpose, dynamic, object-oriented programming language. 
The design purpose of the Python language emphasizes programmer productivity 
and code readability. Python was initially developed by <b>Guido van Rossum</b>. 
It was first released in 1991. Python was inspired by ABC, Haskell, Java, Lisp, Icon
and Perl  programming languages. Python is a high level, general purpose, 
multiplatform, interpreted language. It is a minimalistic language. One of its most 
visible features is that it does not use semicolons nor brackets. Python uses 
indentation instead. 
</p>

<p>
There are two main branches of Python currently. Python 2.x and Python 3.x. Python 3.x
breaks backward compatibility with previous releases of Python. It was created to
correct some design flaws of the language and make the language more clean. 
The most recent version of Python 2.x is 2.7.3, and of Python 3.x 3.3.0.
This tutorial covers Python 2.x versions. Most of the code is written in Python
2.x versions. It will take some time till the software base and programmers will 
migrate to Python 3.x. Today, Python is maintained by a large group of volunteers worldwide. 
Python is open source software. 
</p>

<p>
Python supports several programming styles. It does not force a programmer to a specific 
paradigm. It supports object oriented and procedural programming. There is also a limited 
support for functional programming.
</p>

<p>
The official web site for the Python programming language is 
<a href="http://python.org">python.org</a>
</p>


<h2>Implementations</h2>

<p>
Formally, Python programming language is a specification. There are three main implementations
of Python. CPython, IronPython and Jython. CPython is implemented in C language. It is the
most widely used implementation of Python. When people talk about Python language, they
mostly mean CPython. IronPython is implemented in C#. It is part of the .NET framework. 
Similarly, Jython is an implementation of the Python language in Java. Jython
program is translated into the Java bytecode and executed by the JVM (Java Virtual Machine).
In this tutorial, we will work with CPython.
</p>
 
<h2>Popularity</h2> 
 
<p>
Python belongs to the most popular programming languages.
Both <a href="http://langpop.com/">langpop.com</a> and
<a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">tiobe</a> sites
place Python to top ten languages. Some very popular Python projects include
a distributed source management tool Mercurial, a Django web framework, a PyQt GUI library
or a package management utility called Yum.
</p> 


<h2>Python scripts</h2>

<p>
Every script in the UNIX starts with a <b>shebang</b>. The shebang is the first two 
characters in the script: <b>#!</b>. The shebang is followed by the 
path to the interpreter, which will execute our script. 
</p>

<pre class="code">
#!/usr/bin/python

print "The Python tutorial"
</pre>

<p>
This is our first Python script. The script will print "The Python tutorial" 
string to the console. Python scripts have <b>py</b> extension. 
</p>

<pre>
$ which python
/usr/bin/python
</pre>

<p>
We can find out the path to the Python interpreter using the which command. 
</p>

<p>
Python scripts can be run in two ways. 
</p>

<pre>
$ python first.py
The Python tutorial
</pre>

<p>
Python script is given as an argument to the interpreter. 
</p>

<pre>
$ chmod +x first.py 
$ ./first.py 
The Python tutorial
</pre>

<p>
Or the common way. Use the chmod command to make the file executable. 
And launch it. 
</p>

<hr class="btm">

<p>
The next example shows a simple Ruby script. 
</p>

<pre class="code">
#!/usr/bin/ruby

fruits = ["orange", "apple", "pear", "kiwi"]
fruits.each {|fruits| puts fruits}
</pre>

<p>
Note the shebang and the path to the Ruby interpreter. 
</p>

<pre>
$ ./ruby.rb 
orange
apple
pear
kiwi
</pre>

<p>
This is the output of the Ruby script. 
</p>

<p>
Finally, we show a small Perl script. 
</p>

<pre class="code">
#!/usr/bin/perl

$perl = "Practical Extraction and Report Language\n";

print $perl;
</pre>

<p>
Now the concept should be clear. 
</p>

<p>
In this chapter, we have introduced Python language.
</p>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified December 17, 2012  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>

